package com.hyh.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hyh.ad.common.core.domain.model.SysUser;
import com.hyh.ad.common.utils.SecurityUtils;
import com.hyh.admin.mapper.ContactUsersMapper;
import com.hyh.admin.service.IUserService;
import com.hyh.admin.sys.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    private ContactUsersMapper contactUsersMapper;

    @Autowired
    private SysUserMapper sysUserMapper;

    @Override
    public List<SysUser> getUserList() {
        return contactUsersMapper.selectAllUsers(SecurityUtils.getLoginUser().getUser().getId());
    }

    @Override
    public List<SysUser> searchUser(SysUser sysUser) {
        LambdaQueryWrapper<SysUser> query = new LambdaQueryWrapper<>(sysUser);
        query.orderByAsc(SysUser::getCreateTime);
        return sysUserMapper.selectList(query);
    }

    @Override
    public List<SysUser> searchUserByKeyword(String keyword) {
        LambdaQueryWrapper<SysUser> query = new LambdaQueryWrapper<>();
        query.like(SysUser::getUsername, keyword);
        return sysUserMapper.selectList(query);
    }
}
